%load file
[fle, dirt] = uigetfile('*.png', 'MultiSelect','off'); 
fname = fle; 


%Detect NVs
stitch = imread([dirt '\' fname]);
stitch = imgaussfilt(stitch,1.1);
stitch_resize=imresize(stitch,3);
imshow(stitch_resize); hold on
sensitivity = 0.91;

%Find Dissappearances
dis_fig = figure;
imshow(stitch_resize(:,:,1)); hold on
[d_centers,~] = imfindcircles(stitch_resize(:,:,1),[5 12],'Sensitivity',sensitivity);
dis = size(d_centers,1);
scatter(d_centers(:,1),d_centers(:,2),'r+');

%Find Appearances
app_fig=figure;
imshow(stitch_resize(:,:,2)); hold on
[a_centers,~] = imfindcircles(stitch_resize(:,:,2),[5 12],'Sensitivity',sensitivity);
app = size(a_centers,1);
scatter(a_centers(:,1),a_centers(:,2),'g+');

%Find Orientationn changes
or_fig = figure;
imshow(stitch_resize(:,:,3)); hold on
[o_centers,~] = imfindcircles(stitch_resize(:,:,3),[5 12],'Sensitivity',sensitivity);
or = size(o_centers,1);
try
scatter(o_centers(:,1),o_centers(:,2),'b+');
end

%Print results
fprintf('NVs Appearances (green) = %i \n',app)
fprintf('NVs Disappearances (red) = %i \n',dis)
fprintf('NVs Orientation changes (blue) = %i \n',or)
